package com.huawei.esdk.tp.listener;

import com.huawei.esdk.platform.common.MessageContext;
import com.huawei.esdk.platform.common.ThreadLocalHolder;
import com.huawei.esdk.platform.listener.ISessionListener;
import com.huawei.esdk.tp.authorize.SessionManager;
import com.huawei.esdk.tp.base.BaseService;
import com.huawei.esdk.tp.common.constants.InfoKeys;
import com.huawei.esdk.tp.common.constants.TPConstant;

public class TPSessionListener extends BaseService implements ISessionListener
{
    @Override
    public void sessionCreated(String sessionId)
    {
    }
    
    @Override
    public void sessionDestroyed(String sessionId)
    {
        MessageContext mc = ThreadLocalHolder.get();
        if (null == mc.getEntities().get(InfoKeys.SDK_SESSION_ID.toString()))
        {
            mc.getEntities().put(InfoKeys.SDK_SESSION_ID.toString(), sessionId);
        }
        
        deviceManager.closeConn(TPConstant.DEV_ID_SMC);
        
        SessionManager sessionMgr = SessionManager.getInstance();
        //删除SDKSessionID
        String sdkSession = (String)mc.getEntities().get(InfoKeys.SDK_SESSION_ID.toString());
        sessionMgr.removeSDKSession(sdkSession);
    }
    
}
